package org.huntaway.material.cleaner.mode.imp;

import java.io.File;
import java.io.IOException;

import org.huntaway.material.cleaner.model.bean.InterParameter;
import org.huntaway.material.cleaner.operate.model.InterOperate;

public abstract class BaseOperate implements InterOperate {
	protected void logln(String srt) {
		System.out.println(srt);
	}
	public void open(InterParameter para) {
		String[] cmd = new String[5];
		 cmd[0] = "cmd";  
         cmd[1] = "/c";  
         cmd[2] = "start";  
         cmd[3] = " ";  
         cmd[4] = para.getDest().getPath();  
		exec(cmd);
	}
	public void run(InterParameter para) {
		String[] cmd = new String[5];
		cmd[0] = "cmd";
		cmd[1] = "/c";
		cmd[2] = "start";
		cmd[3] = " ";
		cmd[4] = para.getDest().getPath();
		exec(cmd);
	}
	public void openByAwt(InterParameter para) {
	    try {
			java.awt.Desktop.getDesktop().open(new File(para.getDest().getPath()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
	}
	/**
	 * @see http://javapub.iteye.com/blog/912014
	 * @param cmd
	 */
	private void exec(String[] cmd) {
		try {
			Runtime.getRuntime().exec(cmd);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
